#include<bits/stdc++.h>
using namespace std;
string a1[1000],a2[1000]; 
int main(){
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a1[i]>>a2[i];
	}
	string b;
	while(m--){
		cin>>b;
		cout<<0<<'\n';		
	}
	return 0;
} 
